// pages/distribution/distribution_center.js
const api = require("../../request/api")
const request = require("../../request/request")
const util = require("../../utils/util")
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: '',
    avatarUrl: 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132',
    nickName: '点击显示微信头像',
    if_register: false, 
    res: '',
    shopfinance_data: {},
    eshop_id: '',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.init_data(options)
    this.get_shopfinance()
  },
  get_shopfinance(){
    let params = {
      id : this.data.eshop_id,
    }
    request.post(api.shopfinance, params).then(res=>{
      this.setData({
        shopfinance_data: res
      })
    })
  },
  init_data(options) {
    let uid = util.getAppValue(App.globalData.uid)
    let eshop_id = App.globalData.eshop_id
    if(!uid) {
      uid = 1
    }
    this.setData({
      if_register: App.globalData.if_register,
      uid,
      options,
      eshop_id,
    })
    let avatarUrl = App.globalData.userInfo.avatarUrl
    let nickName = App.globalData.userInfo.nickName
    if (avatarUrl) {
      this.setData({
        avatarUrl,
        nickName
      })
    }
  },
  check_register() {
    if (!this.data.if_register) {
      this.get_user_profile()
    }
  },  

  get_user_profile() {
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: res=>{
        App.globalData.userInfo = res.userInfo
        App.globalData.if_register = true
        this.init_data(this.data.options)
        // let pages = getCurrentPages()
        // let prev_page = pages[pages.length - 2]
        // prev_page.onLoad()
        // util.goBack()
      },
      fail: res=>{
        console.log(res);
      }
    })
  },
  withdrawing() {
    wx.navigateTo({
      url: '/pages/distribution/withdraw',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})